# 编辑异步任务代码
# 注意： 修改完记得重启服务器
# 重启命令 celery -A celery_broker.main worker -l info

from celery_broker.main import celery_app
from celery_broker.sms.ronglian_sms_sdk.SmsSDK import SmsSDK

accId = '8a216da87de15752017e0181a8cb07e5'
accToken = '5db79b9ac97246dfba4095cab868aa55'
appId = '8a216da87de15752017e0181a9e107eb'


@celery_app.task(name='send_sms_code')  # 装饰自定义方法，注册任务，name是给这个进程起一个别名
def send_sms_code(phone, smscode):
    # 利用短信网关发送短信验证码，需要导入容联云的SDK
    # 容联云 https://www.yuntongxun.com/member/main
    # http://doc.yuntongxun.com/space/5a5098313b8496dd00dcdd7f
    # SmsSDK().sendMessage(self, tid: str, mobile: str, datas: tuple)
    # mobile: str 手机号； datas: tuple 数据；tid: str 短信模版

    sdk = SmsSDK(accId, accToken, appId)
    tid = '1'
    datas = (smscode,)
    resp = sdk.sendMessage(tid, phone, datas)
    print(resp)


